var gxdwForm;
var hotelForm;
var xzgxdwFlag;

$(init);

function init(){
    $("#listGrid").jqGrid(
    {
        url : ctx+"/common/extQuery?sqlid=cjxx",
        postData : $("#searchForm").getFormJson(),
        autowidth:true,
        height:(($(window.document).height())-150),
        datatype: "json",    
        colNames : ['网站名称', '网站域名','采集企业','采集区划','数据类型','处理类名','采集状态','操作'],
        colModel : [ 
            {name : "WEBNAME",index : "WEBNAME",width : 150,sortable:false,formatter:function(value,options,row){
            	return "<a href='"+row.BASEURL+"' target='_blank'>"+value+"</a>";
            }}, 
            {name : "BASEURL",index : "BASEURL",width : 150,sortable:false,formatter:function(value){
            	return "<a href='"+value+"' target='_blank'>"+value+"</a>";
            }}, 
            {name : "QYSCOPE",index : "QYSCOPE",width : 100,sortable:false,formatter:function(value){
            	if(value=="0"){
            		return "无";
            	}else if(value=="1"){
            		return "所有税源企业";
            	}else if(value=="2"){
            		return "所有上市公司";
            	}else if(value=="3"){
            		return "非Q板上市公司";
            	}else if(value=="4"){
            		return "Q板上市公司";
            	}
            }}, 
            {name : "QHSCOPE",index : "QHSCOPE",width : 100,sortable:false,formatter:function(value){
            	if(value=="0"){
            		return "无";
            	}else if(value=="1"){
            		return "所有行政区划";
            	}
            }},
            {name : "MODULES",index : "MODULES",width : 150,sortable:false,formatter:function(value){
            	if(!value){
            		return "无";
            	}
            	var html = "";
            	for(var i=0;i<value.length;i++){
            		html+=$("#module"+value.substring(i,(i+1))).attr("alt");
            		if(i<value.length-1){
            			html+="，";
            		}
            	}
            	return html;
            }}, 
            {name : "CLSNAME",index : "CLSNAME",width : 100,sortable:false}, 
            {name : "ISCAP",index : "TBTITLE",width : 100,sortable:false,align:"center",formatter:function(value){
            	if(value=="Y"){
            		return "<span class='labelM'>开启</span>";
            	}else if(value=="N"){
            		return "<span class='labelH'>关闭</span>";
            	}
            }}, 
            {name : "",index : "",width : 150,sortable:false,align:"center",formatter:function(value,options,row){
            return "<span class='tdcz'>" +
                    (row.ISCAP=="N"?"<a title='开启' class='small_btn ok' href=javascript:updateIsCap('Y','" + row.CAPID + "');>开启</a>":"<a title='关闭' class='small_btn off' href=javascript:updateIsCap('N','" + row.CAPID + "');>关闭</a>") +
                    "<a title='删除' class='small_btn del' href=javascript:deleteCJXX('" + row.CAPID + "');>删除</a>" +
                    "</span>";
            }}
        ],
        prmNames:{
            rows:"limit"
        },
        jsonReader :{
            root: "message.list",   
            page: "message.pageNumber",   
            total: "message.totalPage",
            records:"message.totalRow"
        },
        loadtext:"<img src='"+ctx+"/static/images/loading.gif'>&nbsp;&nbsp;拼命加载中...",
        rowNum : 50,
        rowList : [ 50, 100, 150 ],
        pager : "#gridPager",
        mtype: "POST",
        viewrecords : true,
        sortable:false
     });
     //初始化验证
     formValidate("cjForm");
     //自适应屏幕
     $(window).resize(function(){
        $("#listGrid").setGridWidth($(window).width()*0.99);
     });
}

//刷新资源信息
function refreshGrid(){
	$("#listGrid").trigger("reloadGrid",[{page:1}]);
}

function showAddCj(){
	formReset("cjForm");
    qyOpen("新增采集",620,"tztbContent");
}

function saveCJXX(){		
	if (!$("#cjForm").valid()) {
		return;
	}
//	if($("#qyscope").val()=="0"&&$("#qhscope").val()=="0"){
//		qyError("企业和区划必须有一个设为采集！");
//		return;
//	}
	var modules = "";
	$("#cjForm input[name='module']:checked").each(function(){
		modules+=$(this).val();
	});	
//	if(modules==""){
//		qyError("至少选择一个数据类型！");
//		return;
//	}
	qyConfirm("确定执行保存操作吗？",function(value){
		if(!value){
			return;
		}
		var result = doFormService(ctx+"/cjgl/saveCJXX","cjForm","modules",modules);
		if(result){
			qyAlert("保存成功！",function(){
				qyClose();				
				refreshGrid();  
			});
		}
	});
}

function deleteCJXX(capId){
	qyConfirm("确定执行删除操作吗？",function(value){
		if(!value){
			return;
		}		
		var result = doService(ctx+"/cjgl/deleteCJXX","capId",capId);
		if(result){
			qyAlert("操作成功！",function(){
				refreshGrid();
			});
		}
	});
}

function updateIsCap(isCap,capId){
	var result = doService(ctx+"/cjgl/updateIsCap","isCap",isCap,"capId",capId);
	if(result){
		qyAlert("操作成功！",function(){
			refreshGrid();
		});
	}
}
